package by.grsu.hdm.devices;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import by.grsu.hdm.model.HomeDevice;
import by.grsu.hdm.model.INetworkAvailable;
import by.grsu.hdm.reporting.TrafficReportData;

public class NetworkMonitor extends HomeDevice  {
	
	private List<INetworkAvailable> devices;
	
	public NetworkMonitor() {
		this.devices = new ArrayList<INetworkAvailable>();
	}
	
	public NetworkMonitor(String id){
		super(id);
	}
	
	public void registerDevice(INetworkAvailable device)
	{
		this.devices.add(device);
	}
	
	public TrafficReportData getNetworkStatistics()
	{
		long inTraffic = 0;
		long outTraffic = 0;
		
		TrafficReportData reportData = new TrafficReportData();
		
		for (INetworkAvailable device : this.devices) {
			inTraffic += device.getIncomingTraffic();
			outTraffic += device.getOutgoingTraffic();
		}
		
		reportData.setOutgoingTraffic(outTraffic);
		reportData.setIncomingTraffic(inTraffic);
		
		return reportData;
	}
	@Override
	protected void afterTurningOn() {
		System.out.println(getDeviceId() + " is preparing for Power");
		
	}
	
	@Override
	protected void beforeTurningOff() {
		System.out.println(getDeviceId() + " is preparing for shutdown");
	}
}
